//
//  ViewController.m
//  opencv-test
//
//  Created by 6Spring on 2018/2/6.
//  Copyright © 2018年 6Spring. All rights reserved.
//

#import "ViewController.h"
#import "TZImagePickerController.h"
#import "OpenCVUtils.h"

@interface ViewController () <TZImagePickerControllerDelegate>

@property (strong, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) UIImage   *imageRaw;
@property (strong, nonatomic) UIImage   *image;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    [self.imageView setContentScaleFactor:[[UIScreen mainScreen] scale]];
    [self.imageView setContentMode:UIViewContentModeLeft];
    [self.view addSubview:self.imageView];
    
    [self performSelector:@selector(pickImg) withObject:nil afterDelay:1.0];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)pickImg {
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        
    }];
    [self presentViewController:imagePickerVc animated:YES completion:nil];
}

- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto {
    
    self.imageRaw = [photos objectAtIndex:0];
    self.image = [OpenCVUtils Sharpen:self.imageRaw];
    
    [self.imageView setImage:self.image];
}


@end
